package com.oocl.training.parser.impl;

import java.util.Set;

import com.oocl.training.parser.Parser;
import com.oocl.training.pojo.Customer;

/**
 * XML转换器
 * @author GANAB
 *
 */
public class XmlParser implements Parser<String, Set<Customer>> {

	public String parse(Set<Customer> customers) {
		StringBuilder sb = null;
		
		if(customers!=null && customers.size()>0){
			sb = new StringBuilder();
			sb.append("<Customers>\n");
			for(Customer c : customers){
				sb.append("<Customer id=\""+c.getId()+"\" >");
				sb.append("<name>"+c.getName()+"</name>");
				sb.append("<email>"+c.getEmail()+"</email>");
				sb.append("<sex>"+c.getSex()+"</sex>");
				sb.append("<birthday>"+c.getBirthday()+"</birthday>");
				sb.append("</Customer>\n");
			}
			sb.append("</Customers>");
		}
		if(sb!=null) 
			return sb.toString(); 
		return null;
	}
}
